package com.tx.admin.service.rbac.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tx.admin.entity.rbac.UserEntity;
import com.tx.admin.repository.rbac.UserRepository;
import com.tx.admin.security.service.Md5Service;
import com.tx.admin.service.impl.SuperServiceImpl;
import com.tx.admin.service.rbac.UserService;

@Service
@Transactional

 class UserServiceImpl extends SuperServiceImpl<UserEntity> implements UserService{

	@Autowired
	private Md5Service md5Service;
	@Autowired
	private UserRepository userRepository;
	

	
	@Override
	public UserEntity findByUserName(String userName) {
		// TODO Auto-generated method stub
		return userRepository.findByUserName(userName);
	}



	@Override
	public UserEntity save(UserEntity entity) {
		// TODO Auto-generated method stub
		//添加
		if(entity.getId() == null) {
			md5Service.hashUser(entity);
		}else {
			UserEntity o = this.findById(entity.getId());
			//如果密码发生变化
			if(!o.getPassword().equals(entity.getPassword())) {
				md5Service.hashUser(entity);
			}
		}
		return super.save(entity);
	}



	
}
